package com.ruoyi.system.service.download;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class DataQueryFactory {
    private static final Map<String, Supplier<DataQuery>> REGISTRY = new ConcurrentHashMap<>();

    public static void register(String type, Supplier<DataQuery> supplier) {
        if (REGISTRY.containsKey(type.toUpperCase())) {
            throw new IllegalStateException("Type already registered: " + type);
        }
        REGISTRY.put(type.toUpperCase(), supplier);
    }

    public static DataQuery create(String type) {
        Supplier<DataQuery> supplier = REGISTRY.get(type.toUpperCase());
        if (supplier == null) {
            throw new IllegalArgumentException("Unregistered type: " + type);
        }
        return supplier.get();
    }
}